<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>报关单登记系统</title>
<!--#include file="lib/plugins.asp"-->
<style type="text/css">
	.ui-datepicker table {
		border: 0;
	}
	#tablelist{
		min-width:30%;
	}
</style>
<script type="text/javascript">
	$(function() {
        $("#fm_bwtric").validationEngine();
	});
</script>	
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%
if not CheckPostFlag(session("aaPostFlag"),0,15) then call JumpErrorPage(2)
id=saferequest("id",1)
if id="" then id=0 else id=clng(id)
submit=saferequest("submit",0)
if id<>0 then
	sql = "select * from bwtric where bwtric.id="&id
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sql,conn,1,1
	if not rs.eof then
		bwtr=rs("bwtr")
		ic_code=rs("ic_code")
		ic_name=rs("ic_name")
		decno=rs("decno")
	end if
	rs.close
	set rs=nothing
end if
if submit<>"" then
	bwtr=saferequest("bwtr",1)
	ic_code=trim(saferequest("ic_code",0))
	ic_name=trim(saferequest("ic_name",0))
	decno=trim(saferequest("decno",0))
    dept=saferequest("dept",0)
    depts=split(dept,",")
    if ic_code="" or ic_code="" or decno="" then call JumpErrorPage(4)
    call ExecuteCommand("delete * from deptic where icid="&id,false)
	if submit="新增" then
        sql="insert into bwtric(bwtr,ic_code,ic_name,decno) values("&bwtr&",'"&ic_code&"','"&ic_name&"','"&decno&"')"
        id=ExecuteCommand(sql,true)
    end if

    for i=0 to Ubound(depts)
        sql_adddept="insert into deptic(deptid,icid) values("&depts(i)&","&id&")"
        call ExecuteCommand(sql_adddept,false)
    next
    
	if submit="保存" then call ExecuteCommand("update bwtric set bwtr="&bwtr&",ic_code='"&ic_code&"',ic_name='"&ic_name&"',decno='"&decno&"' where id="&id,false)
	if submit="删除" then
        call ExecuteCommand("delete * from bwtric where id="&id,false)
        response.redirect("bwtric.asp")
    end if
    if submit="新增" then response.redirect("bwtric.asp?id="&clng(id))

end if
%>

<body>
<!--#include file="lib/header.asp"-->
<!--#include file="lib/nav.asp"-->
<div id="main">
<!--#include file="lib/col1.asp"-->
<!--#include file="lib/col2.asp"-->
	<div id="col3" role="main">
		<div id="col3_content" class="clearfix">
			<form id="fm_bwtric" name="fm_bwtric" method="post" class="yform" role="application">
                <div class="subcolumns">
                    <div class="c50l">
                      <div class="type-select">
                        <label for="bwtr">被委托人*</label>
                        <select name="bwtr" id="bwtr">
                          <%
                            Set rs_bwtr = Server.CreateObject("ADODB.Recordset")
                            sql = "SELECT id,bwtr FROM bwtr order by id"
                            rs_bwtr.Open sql,conn,1,1
                            do while not rs_bwtr.eof
                          %>
                          <option value="<%=rs_bwtr("id")%>" <%if rs_bwtr("id")=bwtr then response.write("selected='selected'")%>><%=rs_bwtr("bwtr")%></option>
                          <%
                              rs_bwtr.movenext
                            loop
                            rs_bwtr.close
                            set rs_bwtr=nothing
                          %>
                        </select>
                      </div>
                        <div class="type-text">
                            <label for="ic_code">IC卡号*</label>
                            <input name="ic_code" id="ic_code" type="text" size="10" class="validate[required]" value="<%if submit="新增" then response.write("") else response.write(ic_code)%>" />
                        </div>
                        <div class="type-text">
                            <label for="ic_name">报关员*</label>
                            <input name="ic_name" id="ic_name" type="text" size="10" class="validate[required]" value="<%if submit="新增" then response.write("") else response.write(ic_name)%>" />
                        </div>
                        <div class="type-text">
                            <label for="decno">报关员号*</label>
                            <input name="decno" id="decno" type="text" size="10" class="validate[required]" value="<%if submit="新增" then response.write("") else response.write(decno)%>" />
                        </div>
                    </div>
                    <div class="c50r">
                        <fieldset>
                            <legend>关联分组</legend>

                            <%
                                sql_dept = "select * from dept left join (select * from deptic where icid="&id&") as ic on ic.deptid=dept.id"
                                Set rs_dept = Server.CreateObject("ADODB.Recordset")
                                rs_dept.Open sql_dept,conn,1,1
                                do while not rs_dept.eof
                            %>
                            <div class="type-check">
                                <input name="dept" type="checkbox" value="<%=rs_dept("id")%>" <%if rs_dept("id")=rs_dept("deptid") then%>checked="checked"<%end if%>/>
                                <label for="dept"><%=rs_dept("dept")%></label>
                            </div>
                            <%
                                    rs_dept.movenext
                                loop
                                rs_dept.close
                                set rs_dept=nothing
                            %>
                        </fieldset>
                    </div>
                </div>
                <div class="highlight">注意：请仔细填写上述每一个内容，如果填写错误，可能无法正确导入报关数据</div>
				<div class="type-button">
				<%
					if id<>0 then
				%>
					<input type="submit" name="submit" class="submit" value="保存" />
					<input type="submit" name="submit" class="submit" value="删除" />
				<%
					else
				%>
					<input type="submit" name="submit" class="submit" value="新增" />
				<%
					end if
				%>
				</div>
			</form>
			<table id="tablelist">
				<thead>
					<tr><th colspan="6" scope="col">报关卡明细</th></tr>
				</thead>
				<tbody>
					<tr>
						<th scope="col">ID</th>
						<th scope="col">被委托人</th>
						<th scope="col">IC卡号</th>
						<th scope="col">报关员</th>
						<th scope="col">报关员号</th>
						<th scope="col">所属分组</th>
					</tr>
					<%
						sql = "select bwtric.*,bwtr.bwtr as bwtrname from bwtric left join bwtr on bwtric.bwtr=bwtr.id"
						Set rs = Server.CreateObject("ADODB.Recordset")
						rs.Open sql,conn,1,1
						do while not rs.eof
					%>
					<tr>
						<th class="sub" scope="row"><a href="bwtric.asp?id=<%=rs("id")%>"><%=rs("id")%></a></th>
						<td><%=rs("bwtrname")%></td>
						<td><%=rs("ic_code")%></td>
						<td><%=rs("ic_name")%></td>
						<td><%=rs("decno")%></td>
						<td>
                        <%
						sql_dept = "select * from deptic,dept where deptic.deptid=dept.id and deptic.icid="&rs("id")
						Set rs_dept = Server.CreateObject("ADODB.Recordset")
						rs_dept.Open sql_dept,conn,1,1
						do while not rs_dept.eof
                        %>
                        <a href="dept.asp?id=<%=rs_dept("id")%>"><%=rs_dept("dept")%></a><br />
                        <%
							rs_dept.movenext
						loop
						rs_dept.close
						set rs_dept=nothing
                        %>
                        </td>
					</tr>
					<%
						
							rs.movenext
						loop
						rs.close
						set rs=nothing
					
					%>
					
				</tbody>
			</table>
		</div>
	</div>
</div>
<!--#include file="lib/footer.asp"-->
</body>
</html>
<!--#include file="lib/connclose.asp"-->

